# -*- utf-8 -*-
# author : li shi jie
# Email : yr785339493@qq.com
# import requests
#
# while 1:
#     headers = {
#         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'
#     }
#
#     base_url = 'http://www.woshipm.com/rp/1582074.html'
#     reposne = requests.get(base_url, headers=headers, verify=False)
#
#     print(reposne.text)



def line_search(li, val):
    for key, value in enumerate(li):
        if value == val:
            return key
    else:
        return None



def binary_search(li, val):
    left = 0  # 最小值的下标
    right = len(li) - 1  # z最大值的下标
    while left <= right:  # 候选区有值
        # mid是中间值的下标
        mid = (left + right) // 2
        if li[mid] == val:  # 找到了就返回索引
            return mid
        elif li[mid] < val:  # 如果中间值小于找的值，说明要找的值在右边候选区
            left = mid + 1
        else:
            right = mid - 1
    else:
        return None




import time,random


def cal_time(func):
    def inner(*args):
        start = time.time()
        func(*args)
        end = time.time()
        print('run coding time %s' % (end - start))

    return inner

@cal_time
def bubble_sort(li):
    for i in range(len(li)-1):
        exchange = False
        for j in range(len(li)-i-1):
            if li[j] > li[j+1]:
                li[j], li[j+1] = li[j+1], li[j]
                exchange = True
        if not exchange:
            return None

li = list(range(10000))
random.shuffle(li)
bubble_sort(li)


@cal_time
def select_sort(li):
    for i in range(len(li)-1):
        min_loc = i
        for j in range(i+1, len(li)):
            if li[j] < li[min_loc]:
                min_loc = j
        if min_loc != i:
            li[min_loc], li[i] = li[i], li[min_loc]
li2 = list(range(10000))
random.shuffle(li2)
select_sort(li2)

@cal_time
def insert_sort(li):
    for i in range(1, len(li)):
        tmp = li[i]  # 摸到的牌存一个变量中
        j = i - 1  # 模到的牌的前一位的下标
        while li[j] > tmp and j >= 0:
            # 值向右移一位,
            li[j+1] = li[j]
            # 同时j的下标已经是tmp的下标,还要再上前一位
            j -= 1
        # 如果摸到的牌比手里的大,那么直接插入j的后一位
        li[j+1] = tmp
li3 = list(range(10000))
random.shuffle(li3)
insert_sort(li3)









def insert_sort(li):
    for i in range(1, len(li)):
        tmp = li[i]
        j = i-1
        while j >= 0 and li[j] > tmp:
            li[j+1] = li[j]
            j -= 1
        li[j+1] = tmp
























